package com.dz;

import lombok.extern.slf4j.Slf4j;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

import com.dz.sms.SmsProperties;
import com.qcloud.sms.SmsSingleSender;

@SpringBootApplication(scanBasePackages = "com.dz")
@EnableTransactionManagement(proxyTargetClass = true)
@EnableDiscoveryClient
@Slf4j
@EnableConfigurationProperties(value = SmsProperties.class)
@EnableSwagger2
public class DzCustomerApplication {

	@Bean
	public SmsSingleSender smsSingleSender(SmsProperties smsProperties) {
		try {
			return new SmsSingleSender(smsProperties.getAppId(), smsProperties.getAppKey());
		} catch (Exception e) {
			log.error("create sms error", e);
			throw new RuntimeException(e.getMessage());
		}
	}

	public static void main(String[] args) {
		SpringApplication.run(DzCustomerApplication.class, args);
	}
}
